//created by: Joanna Tan

Ext.define('MajorProjectSenchaTouch.controller.Search', {
    extend: 'Ext.app.Controller',
    config:{
        views: ['SearchModule.BasicSearch','SearchModule.ResultList','SearchModule.DisplayResult', 'SearchModule.ResultInfoDisplay',
        'SearchModule.AdvanceSearch', 'BookMarkedModule.ResultListItem', 'ExamPaperModule.ExamSearch', 'ExamPaperModule.ExamResultInfoDisplay', 'ExamPaperModule.DisplayExamResult', 'ExamPaperModule.ExamResultList', 'EResourcesModule.EBooksSearch', 'EResourcesModule.EResources'],
        refs:{
            navView: 'mainNavView',
            eResourcesButton: 'button[action=goEResourcespage]',
            searchResultButton: 'button[action=goSearchResult]',
            searchResultPage: 'searchpage',
            resultListPage: 'resultpage',
            searchAdvanceResultButton: 'button[action=goSearchAdvanceResult]',
            searchAdvanceResultPage: 'searchpage',
            lastResultButton: 'button[action=getnextResult]',
            prevResultButton: 'button[action=getprevResult]',
            resultRangeButton: '#resultrangeBtn',
            resultSummaryButton: '#resultsummaryBtn',
            sorterfield: '#resultsorterField',
            advanceSearchBtn: '#advanceSearchBtn',
            basicselectfield: '#basicselectField',
            basicsearchfield: '#basicsearchField',
            basictogglefield: '#toggleFieldbasic',
            advanceF1selectfield: '#aSelectField1',
            advanceF1searchfield: '#aSearchField1',
            advanceF1togglefield: '#aToggle1', 
            advanceF2selectfield: '#aSelectField2',
            advanceF2searchfield: '#aSearchField2',
            advanceF2togglefield: '#aToggle2', 
            advanceF2condition: '#aChoice2',
            advanceF3selectfield: '#aSelectField3',
            advanceF3searchfield: '#aSearchField3',
            advanceF3togglefield: '#aToggle3', 
            advanceF3condition: '#aChoice3',
            resultListItem: 'resultpage',
            basicSearchButton: '#basicSearchBtn',
            advanceSearchButton:'#advanceSearchSubmit',
            basecon: '#basecon',
            advabasecon: '#advabasecon',
            nextResultsBtn: '#naviBtnNCus',
            prevResultsBtn: '#naviBtnPCus',
            lastTapTimestamp: 0,
            resultListItemEB: 'rlistItem',
			
			// Exam References
			exambasecon: '#exambasecon', 
			examF1selectfield: '#eSelectField1',
            examF1searchfield: '#eSearchField1',
            examF1togglefield: '#eToggle1', 
            examF2selectfield: '#eSelectField2',
            examF2searchfield: '#eSearchField2',
            examF2togglefield: '#eToggle2', 
            examF2condition: '#eChoice2',
            examF3selectfield: '#eSelectField3',
            examF3searchfield: '#eSearchField3',
            examF3togglefield: '#eToggle3', 
            examF3condition: '#eChoice3',
			examSearchButton:'#examSearchSubmit',
			searchExamResultPage: 'searchexampage',
			searchExamButton: 'button[action=goSearchExamResult]',
			prevExamBtn: 'button[action=getprevExamResult]',
			nextExamBtn: 'button[action=getnextExamResult]',
			nextExamResultsBtn: '#naviBtnNExam',
            prevExamResultsBtn: '#naviBtnPExam',
			examResultPage: 'examresultpage',
			examResultSummaryButton: '#examresultsummaryBtn',
			
			// eResources References
			eresourcespage: 'basicebooksfilter',
			eBooksSearchBtn: '#basicEbooksSearchBtn',
			searchEbooksButton: 'button[action=goSearchEbooksResult]',
			ebooksselectfield: '#ebooksselectfield',
            ebookssearchfield: '#ebookssearchfield',
            ebookstogglefield: '#ebooksFieldbasic',
			
			mainBackButton: '#mainBackButton',
			
        },
        control:{
            searchResultButton:{
                tap: 'goSearchResult'
            },
            searchAdvanceResultButton:{
                tap: 'goSearchAdvanceResult'
            },
            lastResultButton:{
                tap: 'getnextResult'
            },
            prevResultButton:{
                tap: 'getprevResult'
            },
            resultListItemEB: {
                ebookTap : 'getLink'
            },
            searchExamButton: {
                tap : 'goSearchExamResult'
            },
			nextExamBtn:{
                tap: 'getnextExamResult'
            },
            prevExamBtn:{
                tap: 'getprevExamResult'
            },
			searchEbooksButton: {
				tap : 'goSearchEbooksResult'
			},
        }
    },
 
    
    /*
|--------------------------------------------------------------------------
| getLink (@author : Joanna Tan)
|--------------------------------------------------------------------------
|
| This function is triggered when the user tap on the ebook button
| on the result list. It will show a pop up window that redirect the
| user to TP eResource Login to view the ebook. 
| 
*/
    getLink: function(item, button, e){
        var record = item.getRecord();
        var elink = record.get('ebooklink');
        console.log(elink);
        if(elink == ''){
        //do nothing
        }
        else{
            window.open(elink);
        }
        e.stopEvent();
    },
       
    /*
|--------------------------------------------------------------------------
| goSearchResult (@author : Joanna Tan)
|--------------------------------------------------------------------------
|
| This function is triggered when the user tap on the Search! 
| button at the Home Page. It will get the search keyword 
| entered by the user and call goCheckKeyWord to replace symbols
| in the keyword. It will then call the loadStore function to retrieve
| data from the API. 
| 
*/
    goSearchResult: function(){        
        //get the search type
        var searchtype = this.getBasicselectfield().getValue();
        
        //get Search Keyword
        var basickeyword = this.getBasicsearchfield().getValue();       
        
        //check if search as a phrase is checked
        var option = this.getBasictogglefield().getValue();
        if(basickeyword == ''){
            Ext.Msg.alert(MajorProjectSenchaTouch.app.noKeywordEnterTitle,  MajorProjectSenchaTouch.app.noKeywordEnterBody);
        }
        else{
            var searchBtn = this.getBasicSearchButton();
            searchBtn.setDisabled(true);
           
            //get the keyword after being process
            var basickeywordProcessTwo = this.goCheckKeyWord(basickeyword);
       
            //set the condition to be pass to load store
            var basicfiltervalue = searchtype + 'U5R' + basickeywordProcessTwo + 'U5R' + option;
            this.loadStore(basicfiltervalue);
        }
    },
/*
|--------------------------------------------------------------------------
| goCheckKeyWord (@author : Joanna Tan)
|--------------------------------------------------------------------------
|
| This function is is use to replace any symbol from the search 
| keyword so as to prevent error when calling for the API. 
| 
*/
	
   goCheckKeyWord: function(value) {
        return ! value ? value: String(value).replace(/%/g, "percent")
        .replace(/'/g, "%27").replace(/\//g, "slash").replace(/!/g, "%21")
        .replace(/\*/g, "%2A").replace(/\#/g, "%23").replace(/\$/g, "%24")
        .replace(/\&/g, "%26").replace(/\(/g, 'openbracket').replace(/\)/g, "closebracket")
        .replace(/\+/g, "%2B").replace(/\@/g, "%40").replace(/\U5R/g, "")
        .replace(/\?/g, "%3F").replace(/\\/g, "%5C").replace(/\[/g, "%5B")
        .replace(/\]/g, "%5D").replace(/\,/g, '%2C').replace(/\;/g, "%3B")
    },
    /*
|--------------------------------------------------------------------------
| loadStore (@author : Joanna Tan)
|--------------------------------------------------------------------------
|
| This function is use to load Results and ResultsInfo Store. It will
| first retrieve the setnumber, number of entries and number of 
| records. The setnumber will be then be use to retrieve the results.
| This is for Basic Search and not Advance Seach. 
|
*/
    loadStore: function(bkw)
    {   
        var con = this.getBasecon();
        con.setMasked({
            xtype: 'loadmask',
            message: 'Please wait...'
        });
        var scope = this;
        //get store
        var resultInfoStore = Ext.getStore('ResultsInfo');
        var resultStore = Ext.getStore('Results');
        
        //empty the store first
        resultInfoStore.removeAll();
        resultStore.removeAll();
        
        var searchBtn = scope.getBasicSearchButton();
        
        //load the store
        resultInfoStore.load({
            callback: function(records, operation, success) {
                // the operation object contains all of the details of the load operation                        
                var setnumber = '';
                var numentries = '';
                var numrecords = '';
                resultInfoStore.each(function(record){
                    setnumber = record.get('setnumber');
                    numentries = record.get('numentries');
                    numrecords = record.get('numrecords');
                });
                
                //check if there is no records found. Show a pop up message if no records found. 
                if(numentries == '0'){
                    Ext.Msg.alert(MajorProjectSenchaTouch.app.noMatchFoundTitle,  MajorProjectSenchaTouch.app.noMatchFoundBody);
                    //hide the loading mask
                    con.setMasked(false);
                    //enable the search button
                    searchBtn.setDisabled(false);
                }
                else if(numentries == ''){
                    Ext.Msg.alert(MajorProjectSenchaTouch.app.errorEncounterTitle,MajorProjectSenchaTouch.app.errorEncounterBody);
                    con.setMasked(false);
                    searchBtn.setDisabled(false);
                }
                else{
                    //get the result range (start)
                    var nextstartresultvar = resultInfoStore.getAt(0).get('currentstart');
                    //get the result range (end)
                    var nextendresultvar = resultInfoStore.getAt(0).get('currentend');
                    //get the number of entries
                    var getmaxnumberrecord = resultInfoStore.getAt(0).get('numentries');
                    //get the search keyword
                    var searchkw = resultInfoStore.getAt(0).get('keyword');
                  
                    var newset = '';
                    if(getmaxnumberrecord <10){
                        //set search condition (setnumber, page (1), sortby(year), numberofrecordstoretrieve(getmaxnumberrecord)) [split by U5R]
                        newset = setnumber + 'U5R1' + 'U5RYearU5R' + getmaxnumberrecord;
                    }
                    else{
                        //set search condition (setnumber, page (1), sortby(year), numberofrecordstoretrieve(10)) [split by U5R]
                        newset = setnumber + 'U5R1' + 'U5RYearU5R10';
                    }
                
                    if(setnumber == ""){
                    //do nothing
                    }
                    else{
                        resultStore.load({
                            url: MajorProjectSenchaTouch.app.serverUrl +'results/retrieveList/' + newset
                        }); 
                    }
                    //hide the loading mask
                    con.setMasked(false);
                    //show the result page
                    scope.pushView('Search Result', 'searchpage');
                    
                    //get the prev page button
                    var prevPageBtn = scope.getPrevResultsBtn();
                    
                    //set and display (result range)
                    var displaytext = 'Result ' + nextstartresultvar + ' - ' + nextendresultvar + ' of ' + getmaxnumberrecord;
                    var resultRangeBtn = scope.getResultRangeButton();
                    resultRangeBtn.setHtml(displaytext);
          
                    //disable the prev page button if the start result range is 1
                    if(nextstartresultvar == 1){
                        prevPageBtn.setDisabled(true);
                    }
                    else{
                        prevPageBtn.setDisabled(false);
                    }
                    
                    //set and display (results found for keyword)
                    var pushtext = 'We found ' + numrecords + ' items(s) matching your search for ' + searchkw;
                    var resultSummaryBtn = scope.getResultSummaryButton();
                    resultSummaryBtn.setHtml(pushtext);
                    
                    searchBtn.setDisabled(false);
                }
            },//callback
            url: MajorProjectSenchaTouch.app.serverUrl +'results/resultList/' + bkw
        });
    },
    
    /*
|--------------------------------------------------------------------------
| getnextResult (@author : Joanna Tan)
|--------------------------------------------------------------------------
|
| This function is triggered when the tap on the > button at the 
| result list. It will get the set number from the resultinfo store
| and retrieve the next set of results. 
|
*/
    getnextResult: function(){
        var scope = this;
        //disable next page button
        var nextPageBtn = this.getNextResultsBtn();
        nextPageBtn.setDisabled(true);
        
        //get the prev page button and set it enabled
        var prevPageBtn = scope.getPrevResultsBtn();
        prevPageBtn.setDisabled(false);
                    
        //get store
        var store = Ext.getStore('ResultsInfo');     
        
        //get the result range (start)
        var nextstartresultvar = store.getAt(0).get('currentstart');
        
        //get the result range (end)
        var nextendresultvar = store.getAt(0).get('currentend');
        
        //get number of entries
        var setnumber = store.getAt(0).get('setnumber');
        
        //get number of entries
        var getmaxnumberrecord = store.getAt(0).get('numentries');
        
        //check if next result range is more then the number of entries
        var checkresult = getmaxnumberrecord - nextendresultvar;
        
        //display message if no more results to show
        if(checkresult == 0){
            Ext.Msg.alert(MajorProjectSenchaTouch.app.noMoreResultTitle,MajorProjectSenchaTouch.app.noMoreResultBody);
            nextPageBtn.setDisabled(false);
        }else{
            //set new start range
            var nextstartresult = nextendresultvar + 1;
            //set new end range
            var nextendresult = nextendresultvar + 10;
        
            //reload result list dataview
            var resultStore = Ext.getStore('Results');
            resultStore.removeAll();        
            var resultList = this.getResultListPage();
            resultList.destroy();
            var searchResultPage = this.getSearchResultPage();
            resultList = Ext.create('MajorProjectSenchaTouch.view.SearchModule.ResultList');
            searchResultPage.add(resultList);
            
            var newset = '';
            if(checkresult < 10){
                //set search condition (setnumber, page (nextstartresult), sortby(year), numberofrecordstoretrieve(checkresult)) [split by U5R]
                newset = setnumber + 'U5R' + nextstartresult + 'U5RYearU5R' + checkresult;
                nextendresult = nextendresultvar + checkresult;
            }
            else{
                //set search condition (setnumber, page (nextstartresult), sortby(year), numberofrecordstoretrieve(10)) [split by U5R]
                newset = setnumber + 'U5R' + nextstartresult + 'U5RYearU5R10';
            }
           
            //load next page
            resultStore.load({
                callback: function(records, operation, success) {
                    //get the current page number
                    var getcurrentpagenum = store.getAt(0).get('currentpagenumber');
                    var nextpagenumber = getcurrentpagenum + 1;
                    
                    //set currentstart in store to nextstartresult
                    store.getAt(0).set('currentstart', nextstartresult);
                    //set currentend in store to nextendresult
                    store.getAt(0).set('currentend', nextendresult);
                    //set currentpagenumber in store to nextpagenumber
                    store.getAt(0).set('currentpagenumber', nextpagenumber);
                    
                    //display the record range
                    var displaytext = 'Result ' + nextstartresult + ' - ' + nextendresult + ' of ' + getmaxnumberrecord;
                    var resultRangeBtn = scope.getResultRangeButton();
                    resultRangeBtn.setHtml(displaytext);
                    //enable next page button
                    nextPageBtn.setDisabled(false);
                },//callback
                url: MajorProjectSenchaTouch.app.serverUrl +'results/retrieveList/' + newset
            });
        }
    },
    
    /*
|--------------------------------------------------------------------------
| getprevResult (@author : Joanna Tan)
|--------------------------------------------------------------------------
|
| This function is triggered when the tap on the < button at the 
| result list. It will get the set number from the resultinfo store
| and retrieve the previous set of results. 
|
*/
    getprevResult: function(){
        var scope = this;
        var store = Ext.getStore('ResultsInfo');
        var newset = '';
        
        //disable prev page button
        var prevPageBtn = this.getPrevResultsBtn();
        prevPageBtn.setDisabled(true);
       
        //get the setnumbers and numbers of entries from the resultInfo store
        var setnumber = '';
        var numentries = '';
        store.each(function(record){
            setnumber = record.get('setnumber');
            numentries = record.get('numentries');
        });
       
        //get the result range (start)
        var prevstartresultvar = store.getAt(0).get('currentstart');
        var prevstartresult = prevstartresultvar - 10;
        
        //get the result range (end)
        var prevendresultvar = store.getAt(0).get('currentend');
        var prevendresult = prevendresultvar - 10;
        
        //get currentpage number
        var getcurrentpagenum = store.getAt(0).get('currentpagenumber');        
        
        if(getcurrentpagenum == 1){
        }
        else{
            //reload result list dataview
            var resultStore = Ext.getStore('Results');
            resultStore.removeAll();        
            var resultList = this.getResultListPage();
            resultList.destroy();
            var searchResultPage = this.getSearchResultPage();
            resultList = Ext.create('MajorProjectSenchaTouch.view.SearchModule.ResultList');
            searchResultPage.add(resultList);
        
            //get the number of records that is being displayed
            var resultdisplaycount = prevendresultvar - prevstartresultvar;
            var resultdisplaycountAdd = resultdisplaycount + 1;
            if(resultdisplaycount < 9){
                prevstartresult = prevstartresultvar - 10;
                newset = setnumber + 'U5R' + prevstartresult + 'U5RnaU5R10';
                prevendresult = prevendresultvar- resultdisplaycountAdd;
            }
            else{
                newset = setnumber + 'U5R' + prevstartresult + 'U5RnaU5R10';
            }
            //load prev page
            resultStore.load({
                callback: function(records, operation, success) {
                    var prevpagenumber = getcurrentpagenum - 1;
                    store.getAt(0).set('currentstart', prevstartresult);
                    store.getAt(0).set('currentend', prevendresult);
                    store.getAt(0).set('currentpagenumber', prevpagenumber);
         
                    //display page range
                    var displaytext = 'Result ' + prevstartresult + ' - ' + prevendresult + ' of ' + numentries;
                    var resultRangeBtn = scope.getResultRangeButton();
                    resultRangeBtn.setHtml(displaytext);
                    //disable prev page button if it's already at the first result
                    if(prevstartresult == 1){
                        prevPageBtn.setDisabled(true);
                    }
                    else{
                        prevPageBtn.setDisabled(false);
                    }
                },//callback
                url: MajorProjectSenchaTouch.app.serverUrl + 'results/retrieveList/' + newset
            });
        }
    },
	
/*
|--------------------------------------------------------------------------
| getnextExamResult (@author : Sean Yow)
|--------------------------------------------------------------------------
|
| This function is triggered when the tap on the > button at the 
| exam result list. It will get the set number from the resultinfo store
| and retrieve the next set of results. 
|
*/
	
	getnextExamResult: function(){
        var scope = this;
        //disable next page button
        var nextPageBtn = this.getNextExamResultsBtn();
        nextPageBtn.setDisabled(true);
        
        //get the prev page button and set it enabled
        var prevPageBtn = scope.getPrevExamResultsBtn();
        prevPageBtn.setDisabled(false);
                    
        //get store
        var store = Ext.getStore('ResultsInfo');     
        
        //get the result range (start)
        var nextstartresultvar = store.getAt(0).get('currentstart');
        
        //get the result range (end)
        var nextendresultvar = store.getAt(0).get('currentend');
        
        //get number of entries
        var setnumber = store.getAt(0).get('setnumber');
        
        //get number of entries
        var getmaxnumberrecord = store.getAt(0).get('numentries');
        
        //check if next result range is more then the number of entries
        var checkresult = getmaxnumberrecord - nextendresultvar;
        
        //display message if no more results to show
        if(checkresult == 0){
            Ext.Msg.alert(MajorProjectSenchaTouch.app.noMoreResultTitle,MajorProjectSenchaTouch.app.noMoreResultBody);
            nextPageBtn.setDisabled(false);
        }else{
            //set new start range
            var nextstartresult = nextendresultvar + 1;
            //set new end range
            var nextendresult = nextendresultvar + 10;
        
            //reload result list dataview
            var resultStore = Ext.getStore('Results');
            resultStore.removeAll();        
            var resultList = this.getExamResultPage();
            resultList.destroy();
            var searchResultPage = this.getSearchExamResultPage();
            resultList = Ext.create('MajorProjectSenchaTouch.view.ExamPaperModule.ExamResultList');
            searchResultPage.add(resultList);
            
            var newset = '';
            if(checkresult < 10){
                //set search condition (setnumber, page (nextstartresult), sortby(year), numberofrecordstoretrieve(checkresult)) [split by U5R]
                newset = setnumber + 'U5R' + nextstartresult + 'U5RYearU5R' + checkresult;
                nextendresult = nextendresultvar + checkresult;
            }
            else{
                //set search condition (setnumber, page (nextstartresult), sortby(year), numberofrecordstoretrieve(10)) [split by U5R]
                newset = setnumber + 'U5R' + nextstartresult + 'U5RYearU5R10';
            }
           
            //load next page
            resultStore.load({
                callback: function(records, operation, success) {
                    //get the current page number
                    var getcurrentpagenum = store.getAt(0).get('currentpagenumber');
                    var nextpagenumber = getcurrentpagenum + 1;
                    
                    //set currentstart in store to nextstartresult
                    store.getAt(0).set('currentstart', nextstartresult);
                    //set currentend in store to nextendresult
                    store.getAt(0).set('currentend', nextendresult);
                    //set currentpagenumber in store to nextpagenumber
                    store.getAt(0).set('currentpagenumber', nextpagenumber);
                    
                    //display the record range
                    var displaytext = 'Result ' + nextstartresult + ' - ' + nextendresult + ' of ' + getmaxnumberrecord;
                    var resultRangeBtn = scope.getResultRangeButton();
                    resultRangeBtn.setHtml(displaytext);
                    //enable next page button
                    nextPageBtn.setDisabled(false);
                },//callback
                url: MajorProjectSenchaTouch.app.serverUrl +'results/retrieveExamList/' + newset
            });
        }
    },

/*
|--------------------------------------------------------------------------
| getprevExamResult (@author : Sean Yow)
|--------------------------------------------------------------------------
|
| This function is triggered when the tap on the < button at the 
| exam result list. It will get the set number from the resultinfo store
| and retrieve the previous set of results. 
|
*/

    getprevExamResult: function(){
        var scope = this;
        var store = Ext.getStore('ResultsInfo');
        var newset = '';
        
        //disable prev page button
        var prevPageBtn = this.getPrevExamResultsBtn();
        prevPageBtn.setDisabled(true);
       
        //get the setnumbers and numbers of entries from the resultInfo store
        var setnumber = '';
        var numentries = '';
        store.each(function(record){
            setnumber = record.get('setnumber');
            numentries = record.get('numentries');
        });
       
        //get the result range (start)
        var prevstartresultvar = store.getAt(0).get('currentstart');
        var prevstartresult = prevstartresultvar - 10;
        
        //get the result range (end)
        var prevendresultvar = store.getAt(0).get('currentend');
        var prevendresult = prevendresultvar - 10;
        
        //get currentpage number
        var getcurrentpagenum = store.getAt(0).get('currentpagenumber');        
        
        if(getcurrentpagenum == 1){
        }
        else{
            //reload result list dataview
            var resultStore = Ext.getStore('Results');
            resultStore.removeAll();        
            var resultList = this.getExamResultPage();
            resultList.destroy();
            var searchResultPage = this.getSearchExamResultPage();
            resultList = Ext.create('MajorProjectSenchaTouch.view.ExamPaperModule.ExamResultList');
            searchResultPage.add(resultList);
        
            //get the number of records that is being displayed
            var resultdisplaycount = prevendresultvar - prevstartresultvar;
            var resultdisplaycountAdd = resultdisplaycount + 1;
            if(resultdisplaycount < 9){
                prevstartresult = prevstartresultvar - 10;
                newset = setnumber + 'U5R' + prevstartresult + 'U5RnaU5R10';
                prevendresult = prevendresultvar- resultdisplaycountAdd;
            }
            else{
                newset = setnumber + 'U5R' + prevstartresult + 'U5RnaU5R10';
            }
            //load prev page
            resultStore.load({
                callback: function(records, operation, success) {
                    var prevpagenumber = getcurrentpagenum - 1;
                    store.getAt(0).set('currentstart', prevstartresult);
                    store.getAt(0).set('currentend', prevendresult);
                    store.getAt(0).set('currentpagenumber', prevpagenumber);
         
                    //display page range
                    var displaytext = 'Result ' + prevstartresult + ' - ' + prevendresult + ' of ' + numentries;
                    var resultRangeBtn = scope.getResultRangeButton();
                    resultRangeBtn.setHtml(displaytext);
                    //disable prev page button if it's already at the first result
                    if(prevstartresult == 1){
                        prevPageBtn.setDisabled(true);
                    }
                    else{
                        prevPageBtn.setDisabled(false);
                    }
                },//callback
                url: MajorProjectSenchaTouch.app.serverUrl + 'results/retrieveExamList/' + newset
            });
        }
    },

    /*
|--------------------------------------------------------------------------
| goSortResult (@author : Joanna Tan)
|--------------------------------------------------------------------------
|
| This function is triggered when the user change the value of the
| picker at the result list. It will get the value user selected and sort
| the results. 
|
*/
    goSortResult: function(){
        var scope = this;
        var sortfield = this.getSorterfield();
        var sortkey = sortfield.getValue();
        //load the stores
        var store = Ext.getStore('ResultsInfo');     
        var resultStore = Ext.getStore('Results');
                
        //reload result list dataview
        resultStore.removeAll();        
        var resultList = this.getResultListPage();
        resultList.destroy();
        var searchResultPage = this.getSearchResultPage();
        resultList = Ext.create('MajorProjectSenchaTouch.view.SearchModule.ResultList');
        searchResultPage.add(resultList);
            
        //get the current set of result setnumber and numentries
        var setnumber = '';
        var numentries = '';
        store.each(function(record){
            setnumber = record.get('setnumber');
            numentries = record.get('numentries');
        });
        
        //reset the result range display to 1 - 10
        var getcurrentpagenum = '1';
        var nextpagenumber = '10';
        //set search condition (setnumber, page (1), sortby(sortkey), numberofrecordstoretrieve(10)) [split by U5R]
        var newset = setnumber + 'U5R1' + 'U5R' + sortkey + 'U5R10';
        
        //change the condition if the result have less then 10 records
        if(numentries < 10){
            //set search condition (setnumber, page (1), sortby(sortkey), numberofrecordstoretrieve(numentries)) [split by U5R]
            newset = setnumber + 'U5R1' + 'U5R' + sortkey + 'U5R' + numentries;
            nextpagenumber= numentries;
        }
        //sort and retrieve the results
        resultStore.load({
            callback: function(records, operation, success) {            
                //set currentstart to 1
                store.getAt(0).set('currentstart', getcurrentpagenum);
                //set currentend to nextpagenumber
                store.getAt(0).set('currentend', nextpagenumber);
                //set currentpagenumber to 1
                store.getAt(0).set('currentpagenumber', '1');
                //display the record range
                var displaytext = 'Result ' + getcurrentpagenum + ' - ' + nextpagenumber + ' of ' + numentries
                var resultRangeBtn = scope.getResultRangeButton();
                resultRangeBtn.setHtml(displaytext);
            },//callback
            url: MajorProjectSenchaTouch.app.serverUrl +'results/retrieveList/' + newset
        });
    },
	
/*
|--------------------------------------------------------------------------
| goSearchAdvanceResult (@author : Joanna Tan)
|--------------------------------------------------------------------------
|
| This function is triggered when the user tap on the Search! 
| button at the Advance Search Page. It will get the search keyword 
| entered by the user and call goCheckKeyWord to replace symbols
| in the keyword. It will then call the loadAdvanceStore function to 
| retrieve data from the API. 
| 
*/
    goSearchAdvanceResult: function(){   
        var firstCondition = 'one';
        var secondCondition ='two';
        var thirdCondition = 'three';
        var allCondition = '';
        
        //disable the search button
        var advsearchBtn = this.getAdvanceSearchButton();
        advsearchBtn.setDisabled(true);
        
        //Filter 1
        var advanceF1searchfield = this.getAdvanceF1searchfield();
        var advanceF1searchkw = advanceF1searchfield.getValue();
        
        var advanceF1selectfield = this.getAdvanceF1selectfield();
        var advanceF1searchby = '';
        
        var advanceF1togglefield = this.getAdvanceF1togglefield();
        var advanceF1toggle =  '';
        
        //check if the first search box is empty. (First search field cannot be empty)
        if(advanceF1searchkw == ''){
            Ext.Msg.alert(MajorProjectSenchaTouch.app.advanceNoKeywordTitle,  MajorProjectSenchaTouch.app.advanceNoKeywordBody);
            advsearchBtn.setDisabled(false);
        }
        else{
            //get the searchtype and check if search as a phrase option is selected. 
            advanceF1searchby = advanceF1selectfield.getValue();
            advanceF1toggle = advanceF1togglefield.getValue();
            var advanceF1choice = 'na';
            //get the search keyword
            var advanceF1searchkwProcess = this.goCheckKeyWord(advanceF1searchkw);
            //set first condition.  (searchbytype, serach keyword, toggle option, choice(NA for first filter)) [split by U5R]
            firstCondition = advanceF1searchby + 'U5R' + advanceF1searchkwProcess + 'U5R' + advanceF1toggle + 'U5R' + advanceF1choice;
        
            //Filter2
            //get the searchtype,search keyword, choice (AND/OR/NOT) and check if search as a phrase option is selected. 
            var advanceF2searchfield = this.getAdvanceF2searchfield();
            var advanceF2searchkw = advanceF2searchfield.getValue();
            var advanceF2selectfield = this.getAdvanceF2selectfield();
            var advanceF2togglefield = this.getAdvanceF2togglefield();
            var advanceF2condition = this.getAdvanceF2condition();
            var advanceF2searchby = '';
            var advanceF2toggle =  '';
            var advanceF2choice =  '';
            advanceF2searchby = advanceF2selectfield.getValue();
            advanceF2toggle = advanceF2togglefield.getValue();
            advanceF2choice = advanceF2condition.getValue();
            
            //check the keyword for symbols and replace by calling goCheckKeyWord function
            var advanceF2searchkwProcess = this.goCheckKeyWord(advanceF2searchkw);
            //set second condition.  (searchbytype, serach keyword, toggle option, choice(AND/OR/NOT)) [split by U5R]
            secondCondition = advanceF2searchby + 'U5R' + advanceF2searchkwProcess + 'U5R' + advanceF2toggle + 'U5R' + advanceF2choice;
        
            //Filter 3        
            //get the searchtype,search keyword, choice (AND/OR/NOT) and check if search as a phrase option is selected. 
            var advanceF3searchfield = this.getAdvanceF3searchfield();
            var advanceF3searchkw = advanceF3searchfield.getValue();
            var advanceF3selectfield = this.getAdvanceF3selectfield();         
            var advanceF3togglefield = this.getAdvanceF3togglefield();         
            var advanceF3condition = this.getAdvanceF3condition();
            var advanceF3searchby = '';
            var advanceF3toggle = '';
            var advanceF3choice = '';
            advanceF3searchby = advanceF3selectfield.getValue();
            advanceF3toggle = advanceF3togglefield.getValue();
            advanceF3choice = advanceF3condition.getValue();
            
            //check the keyword for symbols and replace by calling goCheckKeyWord function
            var advanceF3searchkwProcess = this.goCheckKeyWord(advanceF3searchkw);
            //set third condition.  (searchbytype, serach keyword, toggle option, choice(AND/OR/NOT)) [split by U5R]
            thirdCondition = advanceF3searchby + 'U5R' + advanceF3searchkwProcess + 'U5R' + advanceF3toggle + 'U5R' + advanceF3choice;
                    
            //connect all condition together [split by R2E]
            allCondition = firstCondition + 'R2E' + secondCondition + 'R2E' + thirdCondition;
            //call loadAdvancestore method to retrieve results
            this.loadAdvanceStore(allCondition);
        }
    },
/*
|--------------------------------------------------------------------------
| goSearchExamResult (@author : Sean Yow)
|--------------------------------------------------------------------------
|
| This function is triggered when the user tap on the Search! 
| button at the Exam Search Page. It will get the search keyword 
| entered by the user and call goCheckKeyWord to replace symbols
| in the keyword. It will then call the loadExamStore function to 
| retrieve data from the API. 
| 
*/
    goSearchExamResult: function(){   
        var firstCondition = 'one';
        var secondCondition ='two';
        var thirdCondition = 'three';
        var allCondition = '';
		
        //Filter 1
        var examF1searchfield = this.getExamF1searchfield();
        var examF1searchkw = examF1searchfield.getValue();
        
        var examF1selectfield = this.getExamF1selectfield();
        var examF1searchby = '';
        
        var examF1togglefield = this.getExamF1togglefield();
        var examF1toggle =  '';
        
        //check if the first search box is empty. (First search field cannot be empty)
        if(examF1searchkw == ''){
            Ext.Msg.alert(MajorProjectSenchaTouch.app.advanceNoKeywordTitle,  MajorProjectSenchaTouch.app.advanceNoKeywordBody);
        }
        else{
            //get the searchtype and check if search as a phrase option is selected. 
            examF1searchby = examF1selectfield.getValue();
            examF1toggle = examF1togglefield.getValue();
            var examF1choice = 'na';
            //get the search keyword
            var examF1searchkwProcess = this.goCheckKeyWord(examF1searchkw);
            //set first condition.  (searchbytype, serach keyword, toggle option, choice(NA for first filter)) [split by U5R]
            firstCondition = examF1searchby + 'U5R' + examF1searchkwProcess + 'U5R' + examF1toggle + 'U5R' + examF1choice;
        
            //Filter2
            //get the searchtype,search keyword, choice (AND/OR/NOT) and check if search as a phrase option is selected. 
            var examF2searchfield = this.getExamF2searchfield();
            var examF2searchkw = examF2searchfield.getValue();
            var examF2selectfield = this.getExamF2selectfield();
            var examF2togglefield = this.getExamF2togglefield();
            var examF2condition = this.getExamF2condition();
            var examF2searchby = '';
            var examF2toggle =  '';
            var examF2choice =  '';
            examF2searchby = examF2selectfield.getValue();
            examF2toggle = examF2togglefield.getValue();
            examF2choice = examF2condition.getValue();
            
            //check the keyword for symbols and replace by calling goCheckKeyWord function
            var examF2searchkwProcess = this.goCheckKeyWord(examF2searchkw);
            //set second condition.  (searchbytype, serach keyword, toggle option, choice(AND/OR/NOT)) [split by U5R]
            secondCondition = examF2searchby + 'U5R' + examF2searchkwProcess + 'U5R' + examF2toggle + 'U5R' + examF2choice;
        
            //Filter 3        
            //get the searchtype,search keyword, choice (AND/OR/NOT) and check if search as a phrase option is selected. 
            var examF3searchfield = this.getExamF3searchfield();
            var examF3searchkw = examF3searchfield.getValue();
            var examF3selectfield = this.getExamF3selectfield();         
            var examF3togglefield = this.getExamF3togglefield();         
            var examF3condition = this.getExamF3condition();
            var examF3searchby = '';
            var examF3toggle = '';
            var examF3choice = '';
            examF3searchby = examF3selectfield.getValue();
            examF3toggle = examF3togglefield.getValue();
            examF3choice = examF3condition.getValue();
            
            //check the keyword for symbols and replace by calling goCheckKeyWord function
            var examF3searchkwProcess = this.goCheckKeyWord(examF3searchkw);
            //set third condition.  (searchbytype, serach keyword, toggle option, choice(AND/OR/NOT)) [split by U5R]
            thirdCondition = examF3searchby + 'U5R' + examF3searchkwProcess + 'U5R' + examF3toggle + 'U5R' + examF3choice;
                    
            //connect all condition together [split by R2E]
            allCondition = firstCondition + 'R2E' + secondCondition + 'R2E' + thirdCondition;
            //call loadExamStore method to retrieve results
            this.loadExamStore(allCondition);
        }
    },
	
 /*
|--------------------------------------------------------------------------
| loadExamStore (@author : Sean Yow)
|--------------------------------------------------------------------------
|
| This function is use to load Results and ResultsInfo Store. It will
| first retrieve the setnumber, number of entries and number of 
| records. The setnumber will be then be use to retrieve the results.
| This is for Exam Papers Search. 
|
*/
	
	loadExamStore: function(akw)
    {        
        var scope = this;
        var exasearchBtn = this.getExamSearchButton();
        var newset;
        //get the store
        var resultInfoStore = Ext.getStore('ResultsInfo');
        var resultStore = Ext.getStore('Results');
        //clear the store
        resultInfoStore.removeAll();
        resultStore.removeAll();
        //set a loading mask to let user know their request is being process'
        var con = this.getExambasecon();
        con.setMasked({
            xtype: 'loadmask',
            message: 'Please wait...'
        });
        
        //load the store
        resultInfoStore.load({
            callback: function(records, operation, success) {
                // get setnumber, numentries and numrecords in the resultinfo store                    
                var setnumber = '';
                var numentries = '';
                var numrecord = '';
                resultInfoStore.each(function(record){
                    setnumber = record.get('setnumber');
                    numentries = record.get('numentries');
                    numrecord = record.get('numrecords');
                });
                
                //check if there is no records found. Show a pop up message if no records found. 
                if(numentries == '0'){
                    Ext.Msg.alert(MajorProjectSenchaTouch.app.noMatchFoundTitle,  MajorProjectSenchaTouch.app.noMatchFoundBody);
                    //hide the loding mask and enable the search button
                    con.setMasked(false);
                    exasearchBtn.setDisabled(false);
                }
                //Error encounted. API not called. Maybe due to symbol in the the search string not being replace before passing
                else if(numentries == ''){
                    Ext.Msg.alert(MajorProjectSenchaTouch.app.errorEncounterTitle,  MajorProjectSenchaTouch.app.errorEncounterBody);
                    //hide the loding mask and enable the search button
                    con.setMasked(false);
                    exasearchBtn.setDisabled(false);
                }
                else{
                    //get the result range (start)
                    var nextstartresultvar = resultInfoStore.getAt(0).get('currentstart');
                    //get the result range (end)
                    var nextendresultvar = resultInfoStore.getAt(0).get('currentend');
                    //get the numentries
                    var getmaxnumberrecord = resultInfoStore.getAt(0).get('numentries');
                    //get the keyword user entered
                    var searchkw = resultInfoStore.getAt(0).get('keyword');
                
                    if(setnumber == ""){
                    //do nothing, API not called
                    }
                    else{
                        if(getmaxnumberrecord < 10){ 
                            //set search condition (setnumber, page (1), sortby(year), numberofrecordstoretrieve(getmaxnumberrecord)) [split by U5R]
                            newset = setnumber + 'U5R1' + 'U5RYearU5R' + getmaxnumberrecord;
                        }
                        else{
                            //set search condition (setnumber, page (1), sortby(year), numberofrecordstoretrieve(10)) [split by U5R]
                            newset = setnumber + 'U5R1' + 'U5RYearU5R10';
                        }
                        resultStore.load({
                            url: MajorProjectSenchaTouch.app.serverUrl +'results/retrieveExamList/' + newset
                        }); 
                    }
                    //hide the loading mask
                    con.setMasked(false);

                    //show the result page
                    scope.pushView('Exam Search Result', 'searchexampage');
                
                    //enable the search button
                    exasearchBtn.setDisabled(false);
                    
                    //get the prev page button
                    var prevPageBtn = scope.getPrevExamResultsBtn();
        
                    //set and display (result range)
                    var displaytext = 'Result ' + nextstartresultvar + ' - ' + nextendresultvar + ' of ' + getmaxnumberrecord;
                    //disable the prev page button if the start result range is 1
                    if(nextstartresultvar == 1){
                        prevPageBtn.setDisabled(true);
                    }
                    else{
                        prevPageBtn.setDisabled(false);
                    }
                    var resultRangeBtn = scope.getResultRangeButton();
                    resultRangeBtn.setHtml(displaytext);
          
                    //set and display (result found for keyword)
                    var pushtext = 'We found ' + numrecord + ' items(s) matching your search for ' + searchkw;
                    var examresultSummaryBtn = scope.getExamResultSummaryButton();
                    examresultSummaryBtn.setHtml(pushtext);
                }       
            },//callback
            url: MajorProjectSenchaTouch.app.serverUrl +'results/examSearchList/' + akw
        });
    },
	
/*
|--------------------------------------------------------------------------
| goSearchEbooksResult (@author : Sean Yow)
|--------------------------------------------------------------------------
|
| This function is triggered when the user tap on the Search! 
| button at the eBooks Search Page. It will get the search keyword 
| entered by the user and call goCheckKeyWord to replace symbols
| in the keyword. It will then call the loadEbooksStore function to 
| retrieve data from the API. 
| 
*/
	
	goSearchEbooksResult: function(){        
        //get the search type
        var searchtype = this.getEbooksselectfield().getValue();
        
        //get Search Keyword
        var basickeyword = this.getEbookssearchfield().getValue();       
        
        //check if search as a phrase is checked
        var option = this.getEbookstogglefield().getValue();
        if(basickeyword == ''){
            Ext.Msg.alert(MajorProjectSenchaTouch.app.noKeywordEnterTitle,  MajorProjectSenchaTouch.app.noKeywordEnterBody);
        }
        else{
            var searchBtn = this.getEBooksSearchBtn();
            searchBtn.setDisabled(true);
           
            //get the keyword after being process
            var basickeywordProcessTwo = this.goCheckKeyWord(basickeyword);
       
            //set the condition to be pass to load store
            var basicfiltervalue = searchtype + 'U5R' + basickeywordProcessTwo + 'U5R' + option;
            this.loadEbooksStore(basicfiltervalue);
        }
    },
	
 /*
|--------------------------------------------------------------------------
| loadEbooksStore (@author : Sean Yow)
|--------------------------------------------------------------------------
|
| This function is use to load Results and ResultsInfo Store. It will
| first retrieve the setnumber, number of entries and number of 
| records. The setnumber will be then be use to retrieve the results.
| This is for eBooks Search. 
|
*/

	loadEbooksStore: function(bkw)
    {   
        var con = this.getEresourcespage();
        con.setMasked({
            xtype: 'loadmask',
            message: 'Please wait...'
        });
        var scope = this;
        //get store
        var resultInfoStore = Ext.getStore('ResultsInfo');
        var resultStore = Ext.getStore('Results');
        var backBtn = this.getMainBackButton();
        //empty the store first
        resultInfoStore.removeAll();
        resultStore.removeAll();
        
        var searchBtn = scope.getEBooksSearchBtn();
        
        //load the store
        resultInfoStore.load({
            callback: function(records, operation, success) {
                // the operation object contains all of the details of the load operation                        
                var setnumber = '';
                var numentries = '';
                var numrecords = '';
                resultInfoStore.each(function(record){
                    setnumber = record.get('setnumber');
                    numentries = record.get('numentries');
                    numrecords = record.get('numrecords');
                });
                
                //check if there is no records found. Show a pop up message if no records found. 
                if(numentries == '0'){
                    Ext.Msg.alert(MajorProjectSenchaTouch.app.noMatchFoundTitle,  MajorProjectSenchaTouch.app.noMatchFoundBody);
                    //hide the loading mask
                    con.setMasked(false);
                    //enable the search button
                    searchBtn.setDisabled(false);
                }
                else if(numentries == ''){
                    Ext.Msg.alert(MajorProjectSenchaTouch.app.errorEncounterTitle,MajorProjectSenchaTouch.app.errorEncounterBody);
                    con.setMasked(false);
                    searchBtn.setDisabled(false);
                }
                else{
                    //get the result range (start)
                    var nextstartresultvar = resultInfoStore.getAt(0).get('currentstart');
                    //get the result range (end)
                    var nextendresultvar = resultInfoStore.getAt(0).get('currentend');
                    //get the number of entries
                    var getmaxnumberrecord = resultInfoStore.getAt(0).get('numentries');
                    //get the search keyword
                    var searchkw = resultInfoStore.getAt(0).get('keyword');
                  
                    var newset = '';
                    if(getmaxnumberrecord <10){
                        //set search condition (setnumber, page (1), sortby(year), numberofrecordstoretrieve(getmaxnumberrecord)) [split by U5R]
                        newset = setnumber + 'U5R1' + 'U5RYearU5R' + getmaxnumberrecord;
                    }
                    else{
                        //set search condition (setnumber, page (1), sortby(year), numberofrecordstoretrieve(10)) [split by U5R]
                        newset = setnumber + 'U5R1' + 'U5RYearU5R10';
                    }
                
                    if(setnumber == ""){
                    //do nothing
                    }
                    else{
                        resultStore.load({
                            url: MajorProjectSenchaTouch.app.serverUrl +'results/retrieveList/' + newset
                        }); 
                    }
                    //hide the loading mask
                    con.setMasked(false);
                    //show the result page
                    scope.pushView('Search Result', 'searchpage');
					//hide the back button to prevent repetition of back buttons
                    backBtn.setHidden(true);
                    //get the prev page button
                    var prevPageBtn = scope.getPrevResultsBtn();
                    
                    //set and display (result range)
                    var displaytext = 'Result ' + nextstartresultvar + ' - ' + nextendresultvar + ' of ' + getmaxnumberrecord;
                    var resultRangeBtn = scope.getResultRangeButton();
                    resultRangeBtn.setHtml(displaytext);
          
                    //disable the prev page button if the start result range is 1
                    if(nextstartresultvar == 1){
                        prevPageBtn.setDisabled(true);
                    }
                    else{
                        prevPageBtn.setDisabled(false);
                    }
                    
                    //set and display (results found for keyword)
                    var pushtext = 'We found ' + numrecords + ' items(s) matching your search for ' + searchkw;
                    var resultSummaryBtn = scope.getResultSummaryButton();
                    resultSummaryBtn.setHtml(pushtext);
                    
                    searchBtn.setDisabled(false);
                }
            },//callback
            url: MajorProjectSenchaTouch.app.serverUrl +'results/ebooksResultList/' + bkw
        });
    },
	
	
    /*
|--------------------------------------------------------------------------
| loadAdvanceStore (@author : Joanna Tan)
|--------------------------------------------------------------------------
|
| This function is use to load Results and ResultsInfo Store. It will
| first retrieve the setnumber, number of entries and number of 
| records. The setnumber will be then be use to retrieve the results.
| This is for Advance Search and not Basic Seach. 
|
*/
    loadAdvanceStore: function(akw)
    {        
        var scope = this;
        var advsearchBtn = this.getAdvanceSearchButton();
        var newset;
        //get the store
        var resultInfoStore = Ext.getStore('ResultsInfo');
        var resultStore = Ext.getStore('Results');
        //clear the store
        resultInfoStore.removeAll();
        resultStore.removeAll();
        
        //set a loading mask to let user know their request is being process'
        var con = this.getAdvabasecon();
        con.setMasked({
            xtype: 'loadmask',
            message: 'Please wait...'
        });
        
        //load the store
        resultInfoStore.load({
            callback: function(records, operation, success) {
                // get setnumber, numentries and numrecords in the resultinfo store                    
                var setnumber = '';
                var numentries = '';
                var numrecord = '';
                resultInfoStore.each(function(record){
                    setnumber = record.get('setnumber');
                    numentries = record.get('numentries');
                    numrecord = record.get('numrecords');
                });
                
                //check if there is no records found. Show a pop up message if no records found. 
                if(numentries == '0'){
                    Ext.Msg.alert(MajorProjectSenchaTouch.app.noMatchFoundTitle,  MajorProjectSenchaTouch.app.noMatchFoundBody);
                    //hide the loding mask and enable the search button
                    con.setMasked(false);
                    advsearchBtn.setDisabled(false);
                }
                //Error encounted. API not called. Maybe due to symbol in the the search string not being replace before passing
                else if(numentries == ''){
                    Ext.Msg.alert(MajorProjectSenchaTouch.app.errorEncounterTitle,  MajorProjectSenchaTouch.app.errorEncounterBody);
                    //hide the loding mask and enable the search button
                    con.setMasked(false);
                    advsearchBtn.setDisabled(false);
                }
                else{
                    //get the result range (start)
                    var nextstartresultvar = resultInfoStore.getAt(0).get('currentstart');
                    //get the result range (end)
                    var nextendresultvar = resultInfoStore.getAt(0).get('currentend');
                    //get the numentries
                    var getmaxnumberrecord = resultInfoStore.getAt(0).get('numentries');
                    //get the keyword user entered
                    var searchkw = resultInfoStore.getAt(0).get('keyword');
                
                    if(setnumber == ""){
                    //do nothing, API not called
                    }
                    else{
                        if(getmaxnumberrecord < 10){ 
                            //set search condition (setnumber, page (1), sortby(year), numberofrecordstoretrieve(getmaxnumberrecord)) [split by U5R]
                            newset = setnumber + 'U5R1' + 'U5RYearU5R' + getmaxnumberrecord;
                        }
                        else{
                            //set search condition (setnumber, page (1), sortby(year), numberofrecordstoretrieve(10)) [split by U5R]
                            newset = setnumber + 'U5R1' + 'U5RYearU5R10';
                        }
                        resultStore.load({
                            url: MajorProjectSenchaTouch.app.serverUrl +'results/retrieveList/' + newset
                        }); 
                    }
                    //hide the loading mask
                    con.setMasked(false);
                    //show the result page
                    scope.pushView('Search Result', 'searchpage');
                
                    //enable the search button
                    advsearchBtn.setDisabled(false);
                    
                    //get the prev page button
                    var prevPageBtn = scope.getPrevResultsBtn();
        
                    //set and display (result range)
                    var displaytext = 'Result ' + nextstartresultvar + ' - ' + nextendresultvar + ' of ' + getmaxnumberrecord;
                    //disable the prev page button if the start result range is 1
                    if(nextstartresultvar == 1){
                        prevPageBtn.setDisabled(true);
                    }
                    else{
                        prevPageBtn.setDisabled(false);
                    }
                    var resultRangeBtn = scope.getResultRangeButton();
                    resultRangeBtn.setHtml(displaytext);
          
                    //set and display (result found for keyword)
                    var pushtext = 'We found ' + numrecord + ' items(s) matching your search for ' + searchkw;
                    var resultSummaryBtn = scope.getResultSummaryButton();
                    resultSummaryBtn.setHtml(pushtext);
                }       
            },//callback
            url: MajorProjectSenchaTouch.app.serverUrl +'results/advanceSearchList/' + akw
        });
    },
    
    /*
|--------------------------------------------------------------------------
| pushView (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| Set the title of the navigation bar and push the page into the navigation
| view.
|
*/  
	
	
	
    pushView: function(setTitle, setXtype){
        var view = this.getNavView();
        view.push({
            title: setTitle,
            xtype: setXtype
        })
    }
});

